package 剑指offer;

import leetcode.Head;
import leetcode.ListNode;

import java.util.ArrayList;
import java.util.List;

public class Offer06_JZ03 {

    public static ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        ArrayList<Integer> list = new ArrayList<>();
        print(listNode, list);
        return list;
    }

    public static void print(ListNode listNode, ArrayList<Integer> list){
        if(listNode == null) return;;
        print(listNode.next, list);
        list.add(listNode.val);
    }

    public static void main(String[] args) {
        System.out.println(printListFromTailToHead(Head.genList()));
    }
}
